package com.rxyb.rabbit;

import com.rxyb.rabbit.enums.QueueEnums;
import com.rxyb.rabbit.dto.EventDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author YJH
 * @version 1.0
 * @description
 * @date 2020/6/3  18:13
 */
@Component
@Slf4j
public class SendQueue {


    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send(EventDTO eventDTO) {
        QueueEnums queueEnums = QueueEnums.fromCode(eventDTO.getQueueName());
        if (null != queueEnums) {
            log.info("队列发送信息[{}]", QueueEnums.R_LOG_RECORD.getQueue());
            rabbitTemplate.convertAndSend(queueEnums.getExchange(), queueEnums.getRouting(), eventDTO);
        }
    }
}
